import Foundation
import BDKit
import ProgressHUD

class WXApiHandler: NSObject, WXApiManagerDelegate {

    static let shared = WXApiHandler()

    var onWXLoginSuccess: ((String) -> Void)?
    
    private override init() {
        super.init()
    }

    func managerDidRecvMessageResponse(_ response: SendMessageToWXResp) {
        if response.errCode == 0 {
            ProgressHUD.succeed("分享成功！")
        } else {
            ProgressHUD.failed("分享失败!")
        }
    }

    func managerDidRecvLaunchMiniProgram(_ response: WXLaunchMiniProgramResp) {
        guard let unionId = response.extMsg else {
            ProgressHUD.failed("授权失败")
            return
        }
        print("微信小程序回调，unionId:", unionId)
        onWXLoginSuccess?(unionId)
    }
    
    func managerDidRecvAuthResponse(_ response: SendAuthResp) {
        print(response)
    }

    func managerDidRecvAddCardResponse(_ response: AddCardToWXCardPackageResp) {
        print(response)
    }

    func managerDidRecvChooseCardResponse(_ response: WXChooseCardResp) {
        print(response)
    }

    func managerDidRecvChooseInvoiceResponse(_ response: WXChooseInvoiceResp) {
        print(response)
    }

    func managerDidRecvSubscribeMsgResponse(_ response: WXSubscribeMsgResp) {
        print(response)
    }

    func managerDidRecvInvoiceAuthInsertResponse(_ response: WXInvoiceAuthInsertResp) {
        print(response)
    }

    func managerDidRecvShowMessageReq(_ request: ShowMessageFromWXReq) {
        print(request)
    }

    func managerDidRecvLaunchFromWXReq(_ request: LaunchFromWXReq) {
        print(request)
    }
}
